import { ref, onMounted, onUnmounted, Ref, reactive, toRefs } from 'vue'
import { ElForm, ElMessage, ElMessageBox, ElTree } from 'element-plus';
import request from '@/utils/request';

export default function useOptions() {
    // 应用平台
    const appPlatformList = [
        {
            label: 'Android',
            value: 'Android'
        },
        {
            label: 'IOS',
            value:  'IOS',
        },
        {
            label: 'Web/API',
            value: 'Web/API',
        },
    ]
    // 授权能力
    const empowerList = [
        {
            label: '指令分发',
            value: 0
        },
        {
            label: '脑电波',
            value: 1
        },
        {
            label: '大数据服务',
            value: 2
        },
    ]

     // 设备类型列表
     const deviceTypeList = [
        {
            label: '全部',
            value: 0
        },
        {
            label: 'barco mind 1',
            value: 1    
        },
        {
            label: '单通道头环',
            value: 2
        },
    ]
    // 设备状态列表
    const deviceStatusList = [
        {
            label: '全部',
            value: 0
        },
        {
            label: '在线',
            value: 1
        },
        {
            label: '离线',
            value: -1
        },
        {
            label: '故障',
            value: 2
        },
        {
            label: '警告',
            value: 3
        },
    ]
    const appList = ref([])
    
     // 应用平台
    const getAppPlatformList = () => {
        return appPlatformList
    }

    // 获取授权列表
    const getEmpowerList = () => {

        return empowerList
    }
    // 获取设备类型列表
    const getDeviceTypeList = (type = 0) => {
        if (type === 0) {
            return deviceTypeList
        } else {
            let list = deviceTypeList.filter((ele, index) => index > 0)
            return list
        }
       
    }

     // 获取设备状态列表
     const getDeviceStatusList = () => {
        return deviceStatusList
     
    }

    // 
    const getAppList = () => {
        return request({
            url: '/api/plat/app/list',
            method: 'post',
            data: {
                current: 1,
                pageSize: 99999
            }
        }).then((res: any) => {
            // const obj: any = {};
            // const list = res.data.data.reduce((tol: any, cur: any) => {
            //     if (cur.position) {
            //         obj[cur.position] ? "" : (obj[cur.position] = true && tol.push({ label: cur.position, value: cur.position }));
            //     }
            //     return tol;
            // }, []);
           
            let list = res.data.data || []
            list.forEach((ele: any) => {
                ele.label = ele.name
                ele.value = ele.id + ''
            })
            console.log(list)
            appList.value = list
            return list
        })
    }


    // 默认展位号回显
    function getLocationNumber(val: string) {
        return [val[0], val]
    }

 

    // 禁止已经选择过的展位号
    function setDisabledExhibitorNumList(list: any, val: any) {
        list.forEach((exEle: any) => {
            if (exEle.value === val) {
                exEle.disabled = true
            }
            if (exEle.children) {
                setDisabledExhibitorNumList(exEle.children, val)
            }
        })
        // console.log(list)
    }

    onMounted(() => {

    })
    return {
        getAppPlatformList,
        getEmpowerList, 
        getLocationNumber,
        getAppList,
        getDeviceTypeList,
        getDeviceStatusList
    }

}